package cobots.swarm.agents;

import java.awt.geom.Point2D;

import cobots.swarm.main.SwarmState;


public class LeaderAgent extends Agent {

	protected short targetId = -1;
	protected float attractionRadius = 0;
	protected boolean computedCoalition = false;
	
	public LeaderAgent(int id) {
		super(0,0,1,1);
		this.id = (short)id;
	}
	
	public short getTargetId() {
		return targetId;
	}

	public void setTargetId(int targetId) {
		this.targetId = (short)targetId;
	}

	public float getAttractionRadius() {
		return attractionRadius;
	}

	public void setAttractionRadius(float attractionRadius) {
		this.attractionRadius = attractionRadius;		
	}

	public short getId() {
		return id;
	}

	public void setId(short id) {
		this.id = id;
	}

	public boolean isFree() {
		return getTargetId() == -1; //Here it would return true if it is "-1" else it would return "1"
	}
		
	@Override
	public Point2D computeMovement() {
		if (targetId != -1) {
			Target t = SwarmState.target(targetId);
			return moveTowards(t);
		}
		else
			return super.computeMovement();
	}
	
	
	public void releaseTarget() {
		this.targetId = -1;
		
	}
	
	
	public boolean isComputedCoalition() {
		return computedCoalition;
	}

	public void setComputedCoalition(boolean computedCoalition) {
		this.computedCoalition = computedCoalition;
	}

	@Override
	public String toString() {
		return("L["+id+" "+x+" "+y+"] -> "+targetId);
	}
}
